package com.baseframe.sys.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baseframe.common.annotation.SysLog;
import com.baseframe.common.annotation.VisitLog;
import com.baseframe.common.utils.PageUtils;
import com.baseframe.common.utils.R;
import com.baseframe.common.validator.ValidatorUtils;
import com.baseframe.sys.entity.FrameRole;
import com.baseframe.sys.service.IFrameRoleService;

/**
 * 角色管理
 * 
 * @author xuxf
 */
@RestController
@RequestMapping("/frame/role")
public class FrameRoleController extends AbstractController {
	@Autowired
	private IFrameRoleService frameRoleService;
	
	/**
	 * 角色列表
	 */
	@VisitLog("角色列表")
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		PageUtils page = frameRoleService.queryPage(params);

		return R.ok().put("page", page);
	}
	
	/**
	 * 角色列表
	 */
	@VisitLog("角色列表")
	@RequestMapping("/select")
	public R select(){
		List<FrameRole> list = frameRoleService.findAll();
		
		return R.ok().put("list", list);
	}
	
	/**
	 * 角色信息
	 */
	@RequestMapping("/info/{roleId}")
	public R info(@PathVariable("roleId") String roleId){
		FrameRole role = frameRoleService.selectById(roleId);
		
		
//		//查询角色对应的菜单
//		List<Long> menuIdList = sysRoleMenuService.queryMenuIdList(roleId);
//		role.setMenuIdList(menuIdList);
//
//		//查询角色对应的部门
//		List<Long> deptIdList = sysRoleDeptService.queryDeptIdList(new Long[]{roleId});
//		role.setDeptIdList(deptIdList);
		
		return R.ok().put("role", role);
	}
	
	/**
	 * 保存角色
	 */
	@SysLog(value="保存角色", type="新增")
	@RequestMapping("/save")
	public R save(@RequestBody FrameRole role){
		ValidatorUtils.validateEntity(role);
		
		frameRoleService.save(role);
		
		return R.ok();
	}
	
	/**
	 * 修改角色
	 */
	@SysLog(value="修改角色", type="修改")
	@RequestMapping("/update")
	public R update(@RequestBody FrameRole role){
		ValidatorUtils.validateEntity(role);
		
		frameRoleService.update(role);
		
		return R.ok();
	}
	
	/**
	 * 删除角色
	 */
	@SysLog(value="删除角色", type="删除")
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] roleguids){
		frameRoleService.deleteBatch(roleguids);
		
		return R.ok();
	}
}
